package com.spelet.simulation;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.utils.Array;
import com.spelet.Main;

public class Simulation {
	public Character character;
	public Bee theBee;
	public Map map;
	public Bee a,b,c,d,e;
	public Array<Bee>zerglings;
	public int currentLevel;
	public Main main;

	public OrthographicCamera gameCam, gameUICam;
	public Simulation (Main m){
		gameCam = new OrthographicCamera();
		gameCam.zoom = (float)64f*10f/(float)Gdx.graphics.getWidth();
		gameCam.position.set(Gdx.graphics.getWidth()*gameCam.zoom/2,Gdx.graphics.getHeight()*gameCam.zoom/2,0);
		gameUICam = new OrthographicCamera();
		gameUICam.zoom = 1f;
		gameUICam.position.set(Gdx.graphics.getWidth()*gameUICam.zoom/2,Gdx.graphics.getHeight()*gameUICam.zoom/2,0);
		gameUICam.viewportHeight = Gdx.graphics.getHeight();
		gameUICam.viewportWidth = Gdx.graphics.getWidth();
		gameUICam.update();
		currentLevel = 1;
		zerglings = new Array<Bee>();
		main = m;

		character = new Character();
		map = new Map(this);
		map.loadLevel(character, 1);
		theBee = new Bee(map,0,0);

	}

	public int getNextlevel(){
		return currentLevel+1;
	}
	public void customLevel(String leveldata) {
		map.set(leveldata, character);
	}

	public void setLevel(int level) {
		currentLevel = level;
		map.loadLevel(character,level);
		if(currentLevel == 2){
			for(int i=0; i < 100; i++){
				zerglings.add(new Bee(map,i+10,i+10));
			}
		}else{
		   zerglings.clear();
		}
		theBee.resetBee(map);
		
	}
	public void testLevel(String m) {
		map.set(m,character);
//		theBee.resetBee(map);
	}

	public void update () {
		
		character.update(this);
		theBee.update(this);
		for(int i =0; i <zerglings.size; i++){
			zerglings.get(i).update(this);
			
		}

		for (int y = map.blocks[0].length-1; y >= 0; y--) {
			for (int x = 0; x < map.blocks.length; x++) {
				map.blocks[x][y].update(this);
				map.terrainBlocks[x][y].update(this);
			}
		}
	}

	public void restart() {
	}
	public void restartMap() {
		map.restartLevel(character);
		theBee.resetBee(map);
	}
}
